/*
 * Plant.cpp
 *
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses 
 */

#include "Plant.h"
#include "ModelConstants.h"
#include "MovingBomb.h"
#include <iostream>

Plant::Plant(int x, int y, int shoot_frequency, int facing)
    : LivingObject(x, y), shoot_frequency(shoot_frequency), facing(facing) {
    init();
}

Plant::Plant(int id, int x, int y, int shoot_frequency, int facing)
    : LivingObject(id, x, y), shoot_frequency(shoot_frequency), facing(facing) {
    init();
}

void Plant::init() {
    spawning_x = getSpawningX();
    spawning_y = getSpawningY();
    tics = shoot_frequency;
}

void Plant::receiveDamage(int damage, MapObject* from) {
    //No-op
    (void)0;
}

bool Plant::isDestroyed() {
    return false;
}

void Plant::live(Map& map) {
    tics--;
}

bool Plant::canSpawn(Map& map) {
    return tics <= 0;
}

LivingObject* Plant::spawn() {
    tics = shoot_frequency;
    return new MovingBomb(spawning_x, spawning_y, facing);
}

bool Plant::isDepleted() {
    return false;
}

Plant* Plant::clone() {
    return new Plant(*this);
}

ModelObject Plant::getRepresentation() {
    return PLANT;
}

int Plant::getSpawningX() {
    if (facing == RIGHT) {
        return x+1;
    } else if (facing == LEFT) {
        return x-1;
    } else {
        return x;
    }
}

int Plant::getSpawningY() {
    if (facing == UP) {
        return y-1;
    } else if (facing == DOWN) {
        return y+1;
    } else {
        return y;
    }
}

int Plant::getShootFrequency() {
	return this->shoot_frequency;
}

int Plant::getFacing() {
	return this->facing;
}
